//
//  XLTimeWarningView.m
//  XiangLove
//
//  Created by Dgh Hv on 2018/10/30.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLTimeWarningView.h"



@implementation XLTimeWarningView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        //绘制界面显示
        [self initUI];
    }
    
    return self;
}

-(void)initUI
{
    UIView * centerView = [[UIView alloc]init];
    centerView.backgroundColor = KWhiteColor;
    ViewRadius(centerView, 5);
    [self addSubview:centerView];
    
    [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(270, 201));
    }];
    
    UIImageView * warningIcon = [[UIImageView alloc]init];
    warningIcon.image = IMAGE_NAMED(@"pop-zhuyi-n");
    [self addSubview:warningIcon];
    
    [warningIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.bottom.equalTo(centerView.mas_top).offset(43);
        make.size.mas_equalTo(CGSizeMake(86, 86));
    }];
    
    UILabel * nameLabel = [[UILabel alloc]init];
    nameLabel.text = NSStringFormat(@"%@提醒您",[[XLAccountManager shareInstance] model].NickName);
    nameLabel.textColor = RGB_HEX(0x666666);
    nameLabel.font = SYSTEMFONT(12);
    nameLabel.textAlignment = NSTextAlignmentCenter;
    [centerView addSubview:nameLabel];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(centerView.mas_centerX);
        make.top.equalTo(centerView.mas_top).offset(49);
        make.size.mas_equalTo(CGSizeMake(250, 12));
    }];
    
    UILabel * warningLabel = [[UILabel alloc]init];
    warningLabel.textColor = RGB_HEX(0x333333);
    warningLabel.font = SYSTEMFONT(17);
    warningLabel.textAlignment = NSTextAlignmentCenter;
    warningLabel.numberOfLines = 0;
//    warningLabel.text = @"通话将在1分钟后结束！\n是否延长时间？";
    [centerView addSubview:warningLabel];
    
    NSString * content = @"通话将在1分钟后结束！\n      是否延长时间？";
    NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:content];
    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:12];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [content length])];
    [warningLabel setAttributedText:attributedString];
    
    [warningLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(centerView.mas_centerX);
        make.top.equalTo(nameLabel.mas_bottom).offset(20);
//        make.height.equalTo(@46);
    }];
    
    UIView * HView = [[UIView alloc]init];
    HView.backgroundColor = RGB_HEX(0xe1e1e1);
    [centerView addSubview:HView];
    
    [HView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(centerView.mas_bottom).offset(-54);
        make.left.equalTo(centerView.mas_left).offset(0);
        make.right.equalTo(centerView.mas_right).offset(0);
        make.height.equalTo(@0.5);
    }];
    
    UIView * VView = [[UIView alloc]init];
    VView.backgroundColor = RGB_HEX(0xe1e1e1);
    [centerView addSubview:VView];
    
    [VView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(centerView.mas_centerX);
        make.bottom.equalTo(centerView.mas_bottom).offset(0);
        make.width.equalTo(@0.5);
        make.top.equalTo(HView.mas_bottom).offset(0);
    }];
    
    UIButton * nextBtn = [[UIButton alloc]init];
    [nextBtn setTitle:@"下次吧" forState:UIControlStateNormal];
    [nextBtn setTitleColor:RGB_HEX(0x666666) forState:UIControlStateNormal];
    nextBtn.titleLabel.font = SYSTEMFONT(16);
    kWeakSelf(self);
    [nextBtn addTapBlock:^(UIButton *btn) {
        [weakself removeFromSuperview];
    }];
    [centerView addSubview:nextBtn];
    
    [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(centerView.mas_left).offset(0);
        make.right.equalTo(VView.mas_left).offset(0);
        make.top.equalTo(HView.mas_bottom).offset(0);
        make.bottom.equalTo(centerView.mas_bottom).offset(0);
    }];
    
    UIButton * continueBtn = [[UIButton alloc]init];
    [continueBtn setTitle:@"继续聊" forState:UIControlStateNormal];
    [continueBtn setTitleColor:RGB_HEX(0xFFBB01) forState:UIControlStateNormal];
    continueBtn.titleLabel.font = SYSTEMFONT(16);
    [continueBtn addTapBlock:^(UIButton *btn) {
        if(weakself.payBlcok)
        {
            weakself.payBlcok();
        }
        [weakself removeFromSuperview];
    }];
    [centerView addSubview:continueBtn];
    
    [continueBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(VView.mas_right).offset(0);
        make.right.equalTo(centerView.mas_right).offset(0);
        make.top.equalTo(HView.mas_bottom).offset(0);
        make.bottom.equalTo(centerView.mas_bottom).offset(0);
    }];
}

@end
